package com.sinaapp.gavinzhang.jianzhioffer;

import org.junit.Test;

/**
 * 剑指offer第二题
 * 替换字符串
 * Created by gavin on 15-9-2.
 */
public class ReplaceSpace {

    @Test
    public void test()
    {
        StringBuffer str = new StringBuffer("We Are Happy.");
        System.out.println(replaceSpace(str));
    }

    public static String replaceSpace(StringBuffer str) {
        if(str == null)
        {
            return null;
        }
        if(str.length()==0 || str.indexOf(" ")<=0)
        {
            return str.toString();
        }
        return  str.toString().replace(" ","%20");
    }
}
